]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
keyboard: Add generic handling for key actions
authorCarlos Garnacho <carlosg@gnome.org>
Thu, 14 Apr 2022 19:09:27 +0000 (21:09 +0200)
committerFlorian Müllner <fmuellner@gnome.org>
Wed, 10 Aug 2022 17:11:26 +0000 (17:11 +0000)
These actions are defined in the JSON files themselves, allowing
us to migrate away from the sets of pre/post default keys, and fold
them into the JSON files for fuller control on layout and appearance.

As a first migration step, handle the relevant actions in the buttons
created from the JSON files, so we can port these.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2278>

js/ui/keyboard.js

index 44426b2255087da0b8980d6512471c48055e2bb5..3d9c0b392011826e944df88edb5af1c0fd5a6e6a 100644 (file)
@@ -1548,6 +1548,33 @@ var Keyboard = GObject.registerClass({
                 if (!this._latched)
                     this._setActiveLayer(0);
             });
+            if (key.action !== null) {
+                button.connect('pressed', () => {
+                    if (key.action === 'levelSwitch') {
+                        this._setActiveLayer(key.level);
+                        this._setLatched (
+                            key.level === 1 &&
+                                key.iconName === 'keyboard-caps-lock-symbolic');
+                    }
+                });
+                button.connect('released', () => {
+                    if (key.action === 'hide')
+                        this.close();
+                    else if (key.action === 'languageMenu')
+                        this._popupLanguageMenu(button);
+                    else if (key.action === 'emoji')
+                        this._toggleEmoji();
+                });
+            }
+
+            if (key.action === 'levelSwitch' &&
+                key.iconName === 'keyboard-shift-symbolic') {
+                layout.shiftKeys.push(button);
+                if (key.level === 1) {
+                    button.connect('long-press',
+                        () => this._setLatched(true));
+                }
+            }
 
             if (key.action || key.keyval)
                 button.keyButton.add_style_class_name('default-key');
@@ -1556,6 +1583,11 @@ var Keyboard = GObject.registerClass({
         }
     }
 
+    _setLatched(latched) {
+        this._latched = latched;
+        this._setCurrentLevelLatched(this._currentPage, this._latched);
+    }
+
     _popupLanguageMenu(keyActor) {
         if (this._languagePopup)
             this._languagePopup.destroy();